// JavaScript Document


var ind = 0;
var indTime = 0;
var mydates = new Array();
var d = new Date();

//Makes an array of the next 30 days.  This can be then used with dynamic html to fill the day list.
for(i=0; i < 30; i++){
	mydates.push(d.toDateString());
	d.setDate(d.getDate()+1);
}

//Purpose: Add another Event to the RPI Slider Box with a link to the Select Event
//Inputs: Number of events to add
function addElementRPI(count) {
  var ni = document.getElementById('RPI-box');
  var newa;
  var newdiv;
  
  for(ind=0;ind<count;ind++) {
  
	  newa = document.createElement('a');
	  newdiv = document.createElement('div');
	  
	  //Fill Div with the next event, set it as RPI-event class, and Fill link with popup function
	  newa.setAttribute('href','javascript:setVisibleRPI("description",true)');
	  newdiv.setAttribute('class','RPI-event');
	  newdiv.innerHTML = '<h2>' + events.bwEventList.events[ind].summary + '</h2><p>Date: ' + events.bwEventList.events[ind].start.longdate + '<br />Time: ' + events.bwEventList.events[ind].start.time + '<br />Location: ' + events.bwEventList.events[ind].location.address + '</p>';
	  
	  ni.appendChild(newa);  
	  newa.appendChild(newdiv);
  }
}

//Purpose: Add another Date to the Date Slider Box
//Inputs: Number of dates to add
function addElementDate(count) {
  var ni = document.getElementById('Date-box');
  var newdiv;
  
  for(indTime=0;indTime<count;indTime++) {
  
	  newdiv = document.createElement('div');
	  
	  //Fill Div with the next date and set it as date class
	  newdiv.setAttribute('class','dates');
	  newdiv.innerHTML = '<h3>' + mydates[indTime] + '</h3>';
	  
	  ni.appendChild(newdiv);
  }
}

function addElementSort(category) {
	var cat = category;
	var found = 0;
  var ni = document.getElementById('Troy-box');
  var newdiv = document.createElement('div');
  var divIdName = 'my'+indCat+'DivCat';
  newdiv.setAttribute('id',divIdName);
  newdiv.setAttribute('class','Troy-event');

  while (found == 0 && ind3 < 20) {
		if (events.bwEventList.events[ind3].categories[0] == cat || events.bwEventList.events[ind3].categories[1] == cat) {
			
			newdiv.innerHTML = '<h2>' + events.bwEventList.events[ind3].summary + '</h2><p>Date: ' + events.bwEventList.events[ind3].start.longdate + '<br />Time: ' + events.bwEventList.events[ind3].start.time + '<br />Location: ' + events.bwEventList.events[ind3].location.address + '</p>';
			
			found = 1;
		}
		ind3++;
	}
	if (found == 1) {
		ni.appendChild(newdiv);
		indCat++;
	}
	found = 0;
}